package com.example.wn.controller;


import com.example.wn.model.dto.system.LoginDto;
import com.example.wn.model.entity.system.SysUser;
import com.example.wn.model.vo.common.Result;
import com.example.wn.model.vo.common.ResultCodeEnum;
import com.example.wn.model.vo.system.LoginVo;
import com.example.wn.model.vo.system.SysMenuVo;
import com.example.wn.service.SysUserService;
import com.example.wn.utils.AuthContextUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "用户接口")
@RestController
@RequestMapping(path = "/admin/system/index")
public class IndexController {

    @Resource
    private SysUserService sysUserService;

    @Operation(summary = "登录接口")
    @PostMapping("/login")
    public Result login(@RequestBody LoginDto loginDto){
        LoginVo loginVo = sysUserService.login(loginDto);
        return Result.build(loginVo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "获取用户信息")
    @GetMapping("/userinfo")
    public Result getUserInfo(){
        SysUser sysUser = AuthContextUtil.get();
        return Result.build(sysUser, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "登出")
    @GetMapping("/logout")
    public Result logout(@RequestHeader(name = "token")String token){
        sysUserService.logout(token);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }





}
